package br.edu.fafica.pi1.arkhanhorror.view;

import java.awt.BorderLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import br.edu.fafica.pi1.arkhanhorror.control.ControlPrincipal;

public class ViewPrincipal extends JFrame  implements ActionListener {

	private static final long serialVersionUID = 1L;
	private ControlPrincipal control;

	public ViewPrincipal(ControlPrincipal controlPrincipal) {
		this.control = controlPrincipal;
	}

	public void inicializer() {
		this.setJMenuBar(this.getMenu());
		
		JPanel panelTabuleiro = new ViewTabuleiro();
		JScrollPane scrollerTabuleiro = new JScrollPane(panelTabuleiro);
		this.getContentPane().add(scrollerTabuleiro, BorderLayout.CENTER);

		
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setSize(Toolkit.getDefaultToolkit().getScreenSize());
		this.setLocationRelativeTo(null);
		this.setResizable(false);
        this.setVisible(true);
	}

	private JMenuBar getMenu() {
		JMenuBar menu = new JMenuBar();
		JMenu arquivo = new JMenu("Arquivo");
		JMenuItem sair = new JMenuItem("Sair");
		sair.setName("Sair");
		sair.addActionListener(this);
		arquivo.add(sair);
		menu.add(arquivo);
		return menu;
	}

	
	
	
	@Override
	public void actionPerformed(ActionEvent e) {
		Object obj = e.getSource();
        if (obj instanceof JMenuItem) {
        	JMenuItem item = (JMenuItem) obj;
        	if (item.getName().equals("Sair"))
        		this.control.encerrarAplicacao();
        }
	}
}
